from flask import Flask, request

# Flask实例
app = Flask(__name__)

bind_ip = '127.0.0.1'

@app.route("/api", methods=['POST'])
def do_infer():
    """装饰器@app.route定义了在/api上的HTTP POST接口。"""
    # 获取输入字典
    req_json = request.get_json(force=True)
    xinput = req_json['input']

    # 组织返回字典
    res_json = dict()
    res_json['output'] = f'Hello {xinput}! (from {bind_ip})'

    # 返回
    return res_json


if '__main__' == __name__:

    app.run(bind_ip, 6665)
